
<?php
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

$e1 = $_REQUEST["e1"];

//$arr = array(1, 2, 3, 4);
if ($e1) {
    foreach ($e1 as &$value) {
        //$value = $value * 2;

        echo $value . "<br>";
    }
}
//echo $e1;
?>

<link type="text/css" href="css/select2.css" rel="stylesheet" />
<!--<link type="text/css" href="css/select2-bootstrap.css" rel="stylesheet" />-->
<script type="text/javascript" src="js/select2.js"></script>

<script type="text/javascript">
    $(document).ready(function() {
        $("#e1").select2({
            placeholder: "Select a State"
            ,allowClear: true
            ,maximumSelectionSize: 2
            
        });

//        $("#e1").change(function() {
//            if ($("#e1 option:selected").length > 3) {
//                //your code here
//                alert("กรุณาเลือกได้มากที่สุด 3 ตัวเลือก");
//            }
//        });
    });
</script>

<form method="post">
    <?php
    $sql = "select * from tbl_gallery";
    $result = mysql_query($sql);
    ?>
    <select id="e1" name="e1[]" multiple style="width: 250px;">
        <?php
        while ($row = mysql_fetch_object($result)) {
            ?>
            <option value="<?php echo $row->id; ?>"><?php echo $row->pathfile; ?></option>
            <?php
        }
        ?>
    </select>
    <input type="submit">
</form>
